package com.woniuxy.ptapp.app.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.gson.io.GsonSerializer;
import io.jsonwebtoken.security.Keys;
import java.security.Key;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class TokenTest {
    static String sect = "dsadsadsafwqfwqfwqfwqvqwvfwqwqqq  ";
    public static void main(String[] args) {
        Key key = Keys.hmacShaKeyFor(sect.getBytes());
        Map<String,Object> maps = new HashMap<>();
        maps.put("LoginName","张三");
        maps.put("LoginId","1");

        String token = Jwts.builder()
                .setClaims(maps)
                .setExpiration(new Date(System.currentTimeMillis() + 2000))
                .signWith(key,SignatureAlgorithm.HS256)
                .serializeToJsonWith(new GsonSerializer<>(new Gson()))
                .compact();
        System.out.println(token);
    }
}
